local redis = require "resty.redis"

local _M = {}

function _M.get_connection()
    local red = redis:new()
    local ok, err = red:connect("127.0.0.1", 9736)
    ok, err = red:auth("Mina0708##")
    if not ok then
        ngx.log(ngx.ERR, "failed to connect to redis: ", err)
        return nil
    end
    return red
end

function _M.set_keepalive(red)
    local ok, err = red:set_keepalive(10000, 100)
    if not ok then
        ngx.log(ngx.ERR, "failed to set keepalive: ", err)
    end
end

return _M
